package com.ruoyi.gaokao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gaokao.domain.GkCandidateRegistration;
import com.ruoyi.gaokao.service.IGkCandidateRegistrationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 考生报名信息Controller
 * 
 * @author xiaosong
 * @date 2025-07-07
 */
@Api(tags = "高考-考生报名管理")
@RestController
@RequestMapping("/gaokao/CandidateRegistration")
public class GkCandidateRegistrationController extends BaseController
{
    @Autowired
    private IGkCandidateRegistrationService gkCandidateRegistrationService;

    /**
     * 查询考生报名信息列表
     */
    @ApiOperation("高考考生报名信息管理 - 分页查询列表")
    @PreAuthorize("@ss.hasPermi('gaokao:CandidateRegistration:list')")
    @GetMapping("/list")
    public TableDataInfo list(GkCandidateRegistration gkCandidateRegistration)
    {
        startPage();
        List<GkCandidateRegistration> list = gkCandidateRegistrationService.selectGkCandidateRegistrationList(gkCandidateRegistration);
        return getDataTable(list);
    }


    // 增加根据已有记录决定插入还是更新的upsert接口
//    @PreAuthorize("@ss.hasPermi('gaokao:registration:upsert')")
    @Log(title = "考生报名信息", businessType = BusinessType.OTHER)
    @ApiOperation("高考考生报名信息管理 - 插入或更新数据")
    @PostMapping("/upsert")
    public AjaxResult upsert(@RequestBody GkCandidateRegistration gkCandidateRegistration){
        return toAjax(gkCandidateRegistrationService.upsertGkCandidateRegistration(gkCandidateRegistration));
    }



    /**
     * 导出考生报名信息列表
     */
    @PreAuthorize("@ss.hasPermi('gaokao:CandidateRegistration:export')")
    @Log(title = "考生报名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
        @ApiOperation("高考考生报名信息管理 - 导出数据")
    public void export(HttpServletResponse response, GkCandidateRegistration gkCandidateRegistration)
    {
        List<GkCandidateRegistration> list = gkCandidateRegistrationService.selectGkCandidateRegistrationList(gkCandidateRegistration);
        ExcelUtil<GkCandidateRegistration> util = new ExcelUtil<GkCandidateRegistration>(GkCandidateRegistration.class);
        util.exportExcel(response, list, "考生报名信息数据");
    }

    /**
     * 获取考生报名信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('gaokao:CandidateRegistration:query')")
    @GetMapping(value = "/{idNumber}")
        @ApiOperation("高考考生报名信息管理 - 根据ID获取详细信息")
    public AjaxResult getInfo(@PathVariable("idNumber") String idNumber)
    {
        return success(gkCandidateRegistrationService.selectGkCandidateRegistrationByIdNumber(idNumber));
    }

    /**
     * 新增考生报名信息
     */
    @PreAuthorize("@ss.hasPermi('gaokao:CandidateRegistration:add')")
    @Log(title = "考生报名信息", businessType = BusinessType.INSERT)
    @PostMapping
        @ApiOperation("高考考生报名信息管理 - 新增数据")
    public AjaxResult add(@RequestBody GkCandidateRegistration gkCandidateRegistration)
    {
        return toAjax(gkCandidateRegistrationService.insertGkCandidateRegistration(gkCandidateRegistration));
    }

    /**
     * 修改考生报名信息
     */
    @PreAuthorize("@ss.hasPermi('gaokao:CandidateRegistration:edit')")
    @Log(title = "考生报名信息", businessType = BusinessType.UPDATE)
    @PutMapping
        @ApiOperation("高考考生报名信息管理 - 修改数据")
    public AjaxResult edit(@RequestBody GkCandidateRegistration gkCandidateRegistration)
    {
        return toAjax(gkCandidateRegistrationService.updateGkCandidateRegistration(gkCandidateRegistration));
    }

    /**
     * 删除考生报名信息
     */
    @PreAuthorize("@ss.hasPermi('gaokao:CandidateRegistration:remove')")
    @Log(title = "考生报名信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{idNumbers}")
        @ApiOperation("高考考生报名信息管理 - 删除数据")
    public AjaxResult remove(@PathVariable String[] idNumbers)
    {
        return toAjax(gkCandidateRegistrationService.deleteGkCandidateRegistrationByIdNumbers(idNumbers));
    }
}
